<%@page import="com.shsh.safemanage.model.ManageGroup"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.WriteProblemAction"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.UserDao"%>

<script type="text/javascript">
var userIDList = [];
var count = 0;
</script>

<%
{
WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();
List<ManageGroup> manageGroupList = writeProblemAction.getWriterManageGroupList(request);
%>
<table width="500" style="margin-left: 10px">
<%
boolean isBreak = false;
for (int i = 0; i < 1000; i++) {
%>
<tr>
<%
	for (int j = 0; j < 5; j++) {
		int index = i * 5 + j;
		if (index >= manageGroupList.size()) {
			isBreak = true;
			break;
		}
		
		ManageGroup manageGroup = manageGroupList.get(index);
%>
	<td>
	<input type="checkbox" value="<%=manageGroup.getId()%>" id="manageGroupCheck<%=manageGroup.getId()%>" /> <%=manageGroup.getManageGroupName()%>
	<script type="text/javascript">
	userIDList[count++] = <%=manageGroup.getId()%>
	</script>
	</td>
<%
	}
	if (isBreak) {
		break;
	}
%>
</tr>
<%
}
%>
</table>
<input type="button" style="margin-left: 40px" value="确 定" onclick="addManageGroup()" />
<input type="button" style="margin-left: 20px" value="全 选" onclick="checkAll(true)" />
<input type="button" style="margin-left: 20px" value="全不选" onclick="checkAll(false)" />

<script type="text/javascript">
function addManageGroup() {
	openWaitingDialog('waitingDialog');
	
	var userIDs = '';
	for (var i=0; i != userIDList.length; i++) {
		var userID = userIDList[i];
		var element = document.getElementById('manageGroupCheck'+userID);
		if (element != null && element.checked) {
			if (userIDs == '') {
				userIDs = element.value;
			} else {
				userIDs = userIDs + ',' + element.value;
			}
		}
	}
	
	$.dialog.get('manageGroupDialog').close();
	
	$.ajax({
		type:'post',
		url:'choose_manage_group2_process.jsp',
		data:{
			manageGroupID: userIDs,
			depart1ID: getElementValueByID('depart1')
		},
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				closeWaitingDialog('waitingDialog');
				if (obj.isSuccess == 'true') {
					loadPageSection('<%=request.getContextPath()%>/managegroup_list_section.jsp', 'manageGroupListSpan');
				} else {
					$.dialog.alert(obj.error);
				}
			}
		}
	});
}

function checkAll(isChecked) {
	for (var i=0; i != userIDList.length; i++) {
		var userID = userIDList[i];
		var element = document.getElementById('manageGroupCheck'+userID);
		if (element != null) {
			element.checked = isChecked;
		}
	}
}
</script>
<%
}
%>